/**
 * MenuHander.java
 * Handles the myriad menu options.
 * 
 * Copyright (c) 2012 The Javanauts
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this 
 * software and associated documentation files (the "Software"), to deal in the Software 
 * without restriction, including without limitation the rights to use, copy, modify, 
 * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
 * persons to whom the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies or 
 * substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
package edu.utsa.cs.cs4953_2012.abacus;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JOptionPane;

import edu.utsa.cs.cs4953_2012.abacus.Settings.Mode;

/**
 * Event handler for clicking a button.
 * 
 */
public class MenuHandler implements ActionListener {
	@Override
	public void actionPerformed(ActionEvent e) {
		// These are called "Yoda conditions", like if (5 == value)
		if ("About".equals(e.getActionCommand())) {
			String text = "Nepohaultzintzin\n(c) 2012 The Javanauts\nReleased under MIT license.\n";
			text += "THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING\n";
			text += "BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\n";
			text += "NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,\n";
			text += "DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n";
			text += "OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n";
			text += "See license.txt for details.";
			JOptionPane.showMessageDialog(null, text);
		}
		if ("Quit".equals(e.getActionCommand())) {
			System.exit(0);
		}
		if ("Reset Board".equals(e.getActionCommand())) {
			Board.getInstance().Reset();
			Program.content.repaint();
		}

		if ("Settings".equals(e.getActionCommand())) {
			Settings.program.spawnSettingsWindow();
		}
		
		if (e.getActionCommand().equals("Toggle Decimal Numerals"))
			Settings.toggleStatusPanel();
		else if (e.getActionCommand().equals("Toggle Mayan Numerals"))
			Settings.toggleMayanNumerals();
		
		if (e.getActionCommand().equals("Toggle Split Mode")) {
			if (Settings.mode == Mode.NORMAL)
				Settings.mode = Mode.SPLIT;
			else
				Settings.mode = Mode.NORMAL;
			Program.content.repaint();
		}
		
		if (e.getActionCommand().equals("Trivia"))
			Trivia.displayRandomTrivia();
		
		if (e.getActionCommand().equals("Addition"))
			Settings.mode = Mode.NORMAL;
		else if (e.getActionCommand().equals("Multiplication"))
			Settings.mode = Mode.SPLIT;
		
		if (e.getActionCommand().equals("Plain Beads"))
			Settings.board.setBeadSet(0);
		else if (e.getActionCommand().equals("Fancy Beads"))
			Settings.board.setBeadSet(1);
		
		Program.content.repaint();
	}
}